package main

import (
	"fmt"
	"learngo/GoroutineAndChannel/goroutine"
)

func main() {
	/* go goroutine.ScanWebsite("https://www.baidu.com")
	go goroutine.ScanWebsite("https://golang.org")
	go goroutine.ScanWebsite("https://studygolang.com/pkgdoc")

	time.Sleep(5 * time.Second) */

	// channel.OutputSeq()

	/* myChannel := make(chan string)
	go channel.Send(myChannel)

	//main goroutine休眠五秒，比send goroutine长三秒
	channel.ReportNap("receiving goroutine", 5)
	fmt.Println(<-myChannel)
	fmt.Println(<-myChannel) */

	/* sizes := make(chan int)
	go goroutine.ScanWebsite("https://www.baidu.com", sizes)
	go goroutine.ScanWebsite("https://golang.org", sizes)
	go goroutine.ScanWebsite("https://studygolang.com/pkgdoc", sizes)
	fmt.Println(<-sizes)
	fmt.Println(<-sizes)
	fmt.Println(<-sizes) */

	pages := make(chan goroutine.Page)

	urls := []string{
		"https://www.baidu.com",
		"https://studygolang.com/pkgdoc",
		"https://gitee.com/",
	}

	for _, url := range urls {
		go goroutine.ScanWebsite(url, pages)
	}

	for i := 0; i < len(urls); i++ {
		page := <-pages
		fmt.Printf("%s: %d\n", page.URL, page.Size)
	}
}
